package org.bite.lesson09;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Demo902 {
    public static void main(String[] args) throws InterruptedException {
        //创建一个线程池，容量为3
        ExecutorService threadPool = Executors.newFixedThreadPool(3);
        //向池中添加任务
        for(int i = 0; i < 10; i++){
            int taskId = i + 1;
            threadPool.submit(()->{
                System.out.println("执行任务：" + taskId + "," + Thread.currentThread().getName());

            });
            if(taskId % 2 == 0){
                TimeUnit.SECONDS.sleep(1);
            }
        }
    }
}
